﻿using AutoMapper;
using B.Z.BasicData.Domain.Entity.Authorize;
using B.Z.BasicData.ErrorCode;
using B.Z.BasicData.Infrastructure;
using MediatR;

namespace B.Z.BasicData.API.Write.Application.Role
{
    public class UserRoleRemoveCommandHandler : IRequestHandler<UserRoleRemoveCommand, APIResult<int>>
    {
        private readonly IBaseRepository<T_UserRole> urRepository;
        private readonly IMapper mapper;

        public UserRoleRemoveCommandHandler(IBaseRepository<T_UserRole> urRepository, IMapper mapper)
        {
            this.urRepository = urRepository;
            this.mapper = mapper;
        }

        public  Task<APIResult<int>> Handle(UserRoleRemoveCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code = APIEnum.ok;
            result.Message = "删除成功";
            var userRole = urRepository.GetAll().Where(p => p.Rid == request.Rid && p.Uid == request.Uid).ToList();
            result.Data =  urRepository.Del(userRole);
            return  Task.FromResult(result);
        }
    }
}
